<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Oboe: include/oboe/ResultWithValue.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Oboe
   &#160;<span id="projectnumber">1.2</span>
   </div>
   <div id="projectbrief">A library for creating real-time audio apps on Android</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_768f6301d9838e45d679001914ab2803.html">oboe</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">ResultWithValue.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * Copyright (C) 2018 The Android Open Source Project</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> *</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * you may not use this file except in compliance with the License.</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * You may obtain a copy of the License at</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> *</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> *      http://www.apache.org/licenses/LICENSE-2.0</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> *</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * Unless required by applicable law or agreed to in writing, software</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> * See the License for the specific language governing permissions and</span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> * limitations under the License.</span></div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> */</span></div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;</div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="preprocessor">#ifndef OBOE_RESULT_WITH_VALUE_H</span></div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#define OBOE_RESULT_WITH_VALUE_H</span></div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#include &quot;oboe/Definitions.h&quot;</span></div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#include &lt;sstream&gt;</span></div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceoboe.html">oboe</a> {</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html">   47</a></span>&#160;<span class="keyword">class </span><a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue</a> {</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;</div><div class="line"><a name="l00055"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#aae75caa0d16a9e23a012f77fb50c5927">   55</a></span>&#160;    <a class="code" href="classoboe_1_1_result_with_value.html#aae75caa0d16a9e23a012f77fb50c5927">ResultWithValue</a>(<a class="code" href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">oboe::Result</a> <a class="code" href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">error</a>)</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;            : mValue{}</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;            , mError(<a class="code" href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">error</a>) {}</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;</div><div class="line"><a name="l00064"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#a600309367db58d71f0ec16e90f7ebea5">   64</a></span>&#160;    <span class="keyword">explicit</span> <a class="code" href="classoboe_1_1_result_with_value.html#a600309367db58d71f0ec16e90f7ebea5">ResultWithValue</a>(T <a class="code" href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">value</a>)</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;            : mValue(<a class="code" href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">value</a>)</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;            , mError(<a class="code" href="namespaceoboe.html">oboe</a>::<a class="code" href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">Result</a>::OK) {}</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;</div><div class="line"><a name="l00073"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">   73</a></span>&#160;    <a class="code" href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">oboe::Result</a> <a class="code" href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">error</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;        <span class="keywordflow">return</span> mError;</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    }</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">   81</a></span>&#160;    T <a class="code" href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">value</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;        <span class="keywordflow">return</span> mValue;</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;    }</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;</div><div class="line"><a name="l00088"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#ae32b1953b777af7d1d0c94862ca39986">   88</a></span>&#160;    <span class="keyword">explicit</span> <span class="keyword">operator</span> bool()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mError == oboe::Result::OK; }</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;</div><div class="line"><a name="l00100"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#a6fb3c61c5716a045ba48dc5a5dfc8169">  100</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classoboe_1_1_result_with_value.html#a6fb3c61c5716a045ba48dc5a5dfc8169">operator !</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mError != oboe::Result::OK; }</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;</div><div class="line"><a name="l00110"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#af62107817c0bc76047e6b655a78504ba">  110</a></span>&#160;    <span class="keyword">operator</span> <a class="code" href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">Result</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;        <span class="keywordflow">return</span> mError;</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    }</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;</div><div class="line"><a name="l00121"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#a2304c6120e2aad8f2189383a98c7b0a7">  121</a></span>&#160;    <span class="keyword">static</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue&lt;T&gt;</a> <a class="code" href="classoboe_1_1_result_with_value.html#a2304c6120e2aad8f2189383a98c7b0a7">createBasedOnSign</a>(T numericResult){</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;        <span class="comment">// Ensure that the type is either an integer or float</span></div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;        static_assert(std::is_arithmetic&lt;T&gt;::value,</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;                      <span class="stringliteral">&quot;createBasedOnSign can only be called for numeric types (int or float)&quot;</span>);</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;        <span class="keywordflow">if</span> (numericResult &gt;= 0){</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue&lt;T&gt;</a>(numericResult);</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;        } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue&lt;T&gt;</a>(static_cast&lt;Result&gt;(numericResult));</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;        }</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    }</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;</div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;<span class="keyword">private</span>:</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    <span class="keyword">const</span> T             mValue;</div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;    <span class="keyword">const</span> <a class="code" href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">oboe::Result</a>  mError;</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;};</div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00143"></a><span class="lineno"><a class="line" href="namespaceoboe.html#aa403103686222502d1cfc47bafc10aeb">  143</a></span>&#160;std::ostream&amp; <a class="code" href="namespaceoboe.html#aa403103686222502d1cfc47bafc10aeb">operator&lt;&lt;</a>(std::ostream &amp;strm, <span class="keyword">const</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue&lt;T&gt;</a> &amp;result) {</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;    <span class="keywordflow">if</span> (!result) {</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;        strm &lt;&lt; <a class="code" href="namespaceoboe.html#af65aaea3c5d82eee6906664d61c094b3">convertToText</a>(result.<a class="code" href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">error</a>());</div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;    } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;        strm &lt;&lt; result.<a class="code" href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">value</a>();</div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;    }</div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;   <span class="keywordflow">return</span> strm;</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;}</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;</div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;} <span class="comment">// namespace oboe</span></div><div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;</div><div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;</div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;<span class="preprocessor">#endif //OBOE_RESULT_WITH_VALUE_H</span></div><div class="ttc" id="classoboe_1_1_result_with_value_html_a45f5c99a2c9f8fbaca502276f7ebb434"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">oboe::ResultWithValue::value</a></div><div class="ttdeci">T value() const</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:81</div></div>
<div class="ttc" id="classoboe_1_1_result_with_value_html_aae75caa0d16a9e23a012f77fb50c5927"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#aae75caa0d16a9e23a012f77fb50c5927">oboe::ResultWithValue::ResultWithValue</a></div><div class="ttdeci">ResultWithValue(oboe::Result error)</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:55</div></div>
<div class="ttc" id="classoboe_1_1_result_with_value_html_a2304c6120e2aad8f2189383a98c7b0a7"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#a2304c6120e2aad8f2189383a98c7b0a7">oboe::ResultWithValue::createBasedOnSign</a></div><div class="ttdeci">static ResultWithValue&lt; T &gt; createBasedOnSign(T numericResult)</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:121</div></div>
<div class="ttc" id="namespaceoboe_html_aa403103686222502d1cfc47bafc10aeb"><div class="ttname"><a href="namespaceoboe.html#aa403103686222502d1cfc47bafc10aeb">oboe::operator&lt;&lt;</a></div><div class="ttdeci">std::ostream &amp; operator&lt;&lt;(std::ostream &amp;strm, const ResultWithValue&lt; T &gt; &amp;result)</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:143</div></div>
<div class="ttc" id="namespaceoboe_html_af65aaea3c5d82eee6906664d61c094b3"><div class="ttname"><a href="namespaceoboe.html#af65aaea3c5d82eee6906664d61c094b3">oboe::convertToText</a></div><div class="ttdeci">const char * convertToText(FromType input)</div></div>
<div class="ttc" id="classoboe_1_1_result_with_value_html_adfc76ae6db81535c2e82b856975eed41"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">oboe::ResultWithValue::error</a></div><div class="ttdeci">oboe::Result error() const</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:73</div></div>
<div class="ttc" id="classoboe_1_1_result_with_value_html_a6fb3c61c5716a045ba48dc5a5dfc8169"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#a6fb3c61c5716a045ba48dc5a5dfc8169">oboe::ResultWithValue::operator !</a></div><div class="ttdeci">bool operator !() const</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:100</div></div>
<div class="ttc" id="namespaceoboe_html_a486512e787b609c80ba4436f23929af1"><div class="ttname"><a href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">oboe::Result</a></div><div class="ttdeci">Result</div><div class="ttdef"><b>Definition:</b> Definitions.h:131</div></div>
<div class="ttc" id="classoboe_1_1_result_with_value_html_a600309367db58d71f0ec16e90f7ebea5"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#a600309367db58d71f0ec16e90f7ebea5">oboe::ResultWithValue::ResultWithValue</a></div><div class="ttdeci">ResultWithValue(T value)</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:64</div></div>
<div class="ttc" id="namespaceoboe_html"><div class="ttname"><a href="namespaceoboe.html">oboe</a></div><div class="ttdef"><b>Definition:</b> AudioStream.h:31</div></div>
<div class="ttc" id="classoboe_1_1_result_with_value_html"><div class="ttname"><a href="classoboe_1_1_result_with_value.html">oboe::ResultWithValue</a></div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:47</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.15
</small></address>
</body>
</html>
